package com.my.study.validator.chain;

import com.my.study.validator.ValidatorCallback;
import com.my.study.validator.holder.ValidatorContext;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * @author: yidujun
 * @create: 2021/06/15 19:30
 */
@SuppressWarnings({"rawtypes", "unchecked"})
public final class ValidatorChain {

    private List<ValidatorCallback> validators;

    public List<ValidatorCallback> getValidators() {
        return validators;
    }

    public void setValidators(List<ValidatorCallback> validators) {
        synchronized (this) {
            this.validators = validators;
        }
    }

    public void addValidators(List<ValidatorCallback> validators) {
        synchronized (this) {
            if (null == this.validators) {
                validators = new ArrayList<>();
            }
            this.validators.addAll(validators);
        }
    }

    public void doValidate(ValidatorContext context, Object target, String description) {
        for (ValidatorCallback validator : validators) {
            if (!validator.validate(context, target, description)) {

            }
        }
    }
}
